

import UIKit
import AFNetworking

class XSNetworkTool: AFHTTPSessionManager {

    static let sharedNetworkTool:XSNetworkTool = XSNetworkTool()
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private init()
    {
        let url = NSURL(string: "https://api.weibo.com/")
        super.init(baseURL: url, sessionConfiguration: nil)
        
        self.responseSerializer.acceptableContentTypes?.insert("text/plain")
    }

    func getRequestWithParmant(parmant: [String: AnyObject]?, url: String, finished:(results: [String: AnyObject]?, error: NSError?) -> ())
    {
        GET(url, parameters: parmant, success: { (_, result) -> Void in
            
            finished(results: result as? [String: AnyObject], error: nil)
            
            }) { (_, error) -> Void in
        }
    }
    
    func postRequestWithParmant(parmant: [String: AnyObject]?, url: String, finished:(results: [String: AnyObject]?, error: NSError?) -> ())
    {
        POST(url, parameters: parmant, success: { (_, result) -> Void in
            
            finished(results: result as? [String: AnyObject], error: nil)
            
            }) { (_, error) -> Void in
              
               finished(results: nil, error: error)
        }
    }
}
